import 'package:flutter/material.dart';
import 'package:test1/View/MyRowText.dart';
import 'package:test1/bean/User.dart';

class Json_Model_Page extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text("json解析"),
        ),
        body: ListView(
          children: <Widget>[
            MyRowText("json", () => jsonParser()),
          ],
        ),
      ),
    );
  }

  void jsonParser() {
    var map = {
      "name": "zhangsan",
      "email": "123@qq.com",
      "age": 1
    };

    var user = User.fromJson(map);
    print("name:${user.name}");

    var userMap = User("lisi", "321@qq.com", 3).toJson();
    for (var key in userMap.keys) {
      print("${key} : ${userMap[key]}");
    }
  }
}